#include "Flower.h"



Flower::Flower() {
	flowerHeight = 0;
	flowerPosition = 0;
	flowerSpeed = 30; // DO USTALENIA
	flowerWidth = 30;
	flowerStatus = STAY;
	playerOnFlower = false;

	flowerImage = load_bmp("data/kwiat_1.bmp", default_palette );
}

Flower::Flower(FlowerStat status, int speed, int position, int height) {
	flowerHeight = height;
	flowerPosition = position;
	flowerSpeed = speed;
	flowerStatus = status;
	playerOnFlower = false;
	flowerWidth = 100;
	flowerDirection = false;


	if((rand()%3) == 2){
		flowerImage = load_bmp("data/kwiat_2.bmp", default_palette );
	}
	else if((rand()%3) == 2){
		flowerImage = load_bmp("data/kwiat_1.bmp", default_palette );
	}else{
		flowerImage = load_bmp("data/kwiat_3.bmp", default_palette );
	}

}


void Flower::grow(int speed) {
	flowerStatus = GROW;
	flowerSpeed = speed;
}

void Flower::stay(int speed) {
	flowerStatus = STAY;
	flowerSpeed = speed;
}

void Flower::fall(int speed) {
	flowerStatus = FALL;
	flowerSpeed = speed;
}

void Flower::updateHeight()
{
	if((rand()%30) == 3){
		flowerDirection=!flowerDirection;
		flowerSpeed = (rand() % 8) * 1.5;
	}

	if(!flowerDirection){

		if(flowerHeight > 120){
			flowerHeight = flowerHeight - flowerSpeed;
		}
		else{
			flowerDirection = true;
		}
	}
	else{

		flowerHeight = flowerHeight + flowerSpeed;
		if(flowerHeight > 520){
			flowerDirection =false;
		}
	}
}

void Flower::PlayerOnFlower(){
	playerOnFlower = true;
}

void Flower::PlayerOffFlower(){
	playerOnFlower = false;
}

void Flower::GetPos(int & p_flowerHeight, int & p_flowerPosition, int & p_flowerWidth )
{
//	return flowerHeight, flowerPosition, flowerWidth;

	p_flowerHeight=flowerHeight;
	p_flowerPosition=flowerPosition;
	p_flowerWidth=flowerWidth;

}

void Flower::Draw(BITMAP *buffer)
{
	masked_blit(flowerImage, buffer, 0, 0, flowerPosition-20, flowerHeight+90, 133, 400);
}
